<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加联系人</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
        <form id="addAcc_form">
        <div class="fieldset1 tabel_col tabel_col_1 clearFix">
            <div class="fieldBox col_100">
                <div class="label">类型</div>
                <div class="field">
                    <c:forEach items="${bkAccTypCdList }" var="kv" begin="0" step="1" varStatus="status">
                        	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        	<c:if test="${status.index == 0}">
                        		<input type="radio" value="${kv.key }" name="accTypCd" checked />${kv.value }	
                        	</c:if>
                        	<c:if test="${status.index != 0}">
                        		<input type="radio" value="${kv.key }" name="accTypCd" />${kv.value }
                        	</c:if>
                  	</c:forEach>
                  	&nbsp;&nbsp;&nbsp;&nbsp;
                  	<span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">开户行</div>
                <div class="field">
                	<!-- <div class="sqPanel_body" style="min-height: 300px;">
                        	<ul id="tree1"></ul>
                    </div> -->
                    <select name="bkId" id="bkId" data-value=" " validate="{required:true,select:true}">
                       <option value=" ">请选择</option>
                       <c:forEach items="${openBkList }" var="bk">
                     		<option value="${bk.id }">${bk.bkNm }</option>
                     		<c:forEach items="${bk.children }" var="branch">
	                     		<option value="${branch.id }">&nbsp;&nbsp;&nbsp;&nbsp;${branch.bkNm }</option>
	                       </c:forEach>
                       </c:forEach>
                    </select>
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">账号名称</div>
                <div class="field">
                    <input name="accNm" id="accNm" type="text" class="ui-textbox" value="" validate="{required:true}">
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">账号</div>
                <div class="field">
                    <input name="accNo" id="accNo" type="text" class="ui-textbox" value="" validate="{required:true,number:true}">
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_100" >
                <div class="label">支持平台</div>
                <div class="field">
                    <c:forEach items="${sysOrgList }" var="item" begin="0" step="1" varStatus="status">
                        	<input type="checkbox" orgcd="${item.orgCd }" orgid="${item.id }" value="${item.id }" name="orgIds" />${item.orgNm }<br/>	
                  	</c:forEach>
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">账户备注</div>
                <div class="field">
                    <input name="accRem" id="accRem" type="text" class="ui-textbox" value="">
                </div>
            </div>
             <div class="fieldBox col_100">
                <div class="label">付款帐号主体</div>
                <div class="field">
                	
                    <select name="payerMainCd" id="payerMainCd" data-value=" " validate="{required:true,select:true}">
                       <option value=" ">请选择</option>
                       <c:forEach items="${payerMainCdList }" var="item">
                     		<option value="${item.key }">${item.value}</option>
                     		
                       </c:forEach>
                    </select>
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
        </div>
        <div class="btnsBox">
        	<span id="saveNewAcc_Btn" class="sq-button sq-button-hasicon l-dialog-btn-ok"><i class="sqBtnIco_10"></i>保存</span>
        </div>
    </form>
<script>
		$(function() {
		   $("#addAcc_form").ligerForm({
                validate: true
           });
		   $("#saveNewAcc_Btn").click(function(event) {
		    	
		        var form = liger.get("addAcc_form");
		        if (!form.valid()) {
		        	$.ligerDialog.SQalert({content:LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
		            return false;
		        }
		        var data = form.getData();
		        /* $.ligerDialog.hide();
		        if(!data.bkId){
		        	$.ligerDialog.SQalert({content:"请选择开户行！", SQ_type: "warning"});
		        } */
		        //单选框数据
		        var val=$('input:radio[name="accTypCd"]:checked').val();
				if(val){
					data.accTypCd=val;
				}
		        
				//复选框数据
				var _org = $('input:checkbox[name="orgIds"]:checked');
		        //var _orgIds = [];
		        var newJSON = {orgJSON:[]};
		        for(var i = 0; i < _org.length; i++){
		        	if(_org[i].checked){
		        		//_orgIds.push(_org[i].value);
		        		var org = '{orgId:"'+$(_org[i]).attr("orgid")+'",orgCd:"'+$(_org[i]).attr("orgcd")+'"}';
		        		newJSON.orgJSON.push(org);
		        	}
		        }
		        data["orgJSON"] = "["+newJSON.orgJSON+"]";
		        
				var wait_dialog;
				$.ajax({
					type: 'post',
					dataType:'json',
					data:data,
					url: '<%=path%>/system/sysBkAccInfo/add.do',
					beforeSend:function(){
						wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
					},
					success:function(msg){
						wait_dialog.close();
						if(msg.success == 1){
							$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
							//parent.grid.reload();
							parent.$("#clearBtn").click();
							parent.$("#searchBtn").click();
	        				frameElement.dialog.close();
						 }else{
							$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
						 }
					}
				});
		    });
		   SET_popupIframeHeight();
});
		/* function onSelectTree (node) {
			bkId = node.data.id;
		 }	 */
	</script>
</body>
</html>
